package com.example.chat.model;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;
import java.io.Serializable;

/**
 * @author ：YaXing
 * @description：角色权限中间表
 * @date ：2022/3/24 19:09
 */
@Entity
@Table(name = "VDOA006_ROLE_PERMISSION")
@Data
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
@DynamicInsert
@DynamicUpdate
@NoArgsConstructor
public class RolePermission extends BaseEntity implements Serializable {

    private static final long serialVersionUID = 5519733290155626520L;

    @Id
    @GenericGenerator(name = "uuidG", strategy = "org.hibernate.id.UUIDGenerator")
    @GeneratedValue(generator = "uuidG")
    @Column(name = "DOA006_ID")
    private String id;

    /**
     * 角色id
     */
    @Column(name = "DOA006_ROLE_ID")
    private String roleId;

    /**
     * 权限id
     */
    @Column(name = "DOA006_PERMISSION_ID")
    private String permissionId;

    @ManyToOne(targetEntity = Role.class, fetch = FetchType.LAZY)
    @JoinColumn(name = "DOA006_ROLE_ID", updatable = false, insertable = false)
    private Role role;

    @ManyToOne(targetEntity = Permission.class, fetch = FetchType.LAZY)
    @JoinColumn(name = "DOA006_PERMISSION_ID", updatable = false, insertable = false)
    private Permission permission;

    public String getPermissionName() {
        return this.permission.getName();
    }

    /**
     * 是否已删除
     */
    @Column(name = "DOA006_DELETED")
    private Boolean deleted = false;
}
